<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>refs</title>
  </head>

  <body>
    <!--  -->
    <!-- 准备好一个“容器” -->
    <div id="test"></div>
    <div id="test2"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM -->
    <script type="text/javascript" src="js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="js/babel.min.js"></script>
    <!-- <script src="./change_weather.js"></script> -->
  </body>
  <script src="./js/prop-types.js"></script>
  <script type="text/babel">
    class Login extends React.Component {
      state = {
        username: "",
        password: "",
      };
      saveFormData = (dataType) => {
        //   这样写不行，必须写箭头函数,因为下面用到了this
        //   return function(event){
        return (event) => {
          console.log(dataType);
          console.log(event);
          this.setState({
            //   这样写会创造一个属性名叫dataType
            //   dataType:event.target.value
            [dataType]: event.target.value,
          });
        };
      };
      handle_submit = (event) => {
        //   阻止默认跳转
        event.preventDefault();
        console.log("sub");
      };
      render() {
        return (
          <form onSubmit={this.handle_submit}>
            用户名
            <input name="username" onChange={this.saveFormData("username")} />
            密码
            <input name="password" onChange={this.saveFormData("password")} />
          </form>
        );
      }
    }
    ReactDOM.render(<Login />, document.getElementById("test"));
  </script>
</html>
